package mathClass

/*
时间复杂度：O(C)
空间复杂度：O(1)

*/

var monthDays = []int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
var weekDays = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}

func dayOfTheWeek(day int, month int, year int) string {
	// 1971/1/1是Friday
	days := 4
	for i := 1971; i < year; i++ {
		if isLeap(i) {
			days += 366
		} else {
			days += 365
		}
	}
	for i := 1; i < month; i++ {
		days += monthDays[i-1]
		if i == 2 && isLeap(year) {
			days += 1
		}
	}
	days += day
	return weekDays[days%7]
}

func isLeap(year int) bool {
	return (year%4 == 0 && year%100 != 0) || year%400 == 0
}
